package com.fattyCorps.game.controller;

import com.fattyCorps.game.obj.msg.SRet;
import com.fattyCorps.game.obj.msg.client.hero.CCreateHeroMsg;
import com.fattyCorps.game.obj.msg.client.hero.CHeroDetailMsg;
import com.fattyCorps.game.obj.msg.client.hero.CHeroLvUpMsg;
import com.fattyCorps.game.obj.msg.client.hero.CHeroStarUpMsg;
import com.fattyCorps.game.obj.msg.server.hero.SHeroDetailMsg;
import com.fattyCorps.game.obj.msg.server.hero.SHeroLvUpMsg;
import com.fattyCorps.game.service.HeroService;
import com.fattyCorps.game.util.GameJwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/hero")
public class HeroController {

    @Autowired
    HeroService heroService;

    @PostMapping("/create")
    public SRet create(HttpServletRequest request, @RequestBody CCreateHeroMsg cCreateHeroMsg){
//        调用HeroService的createHero方法
        Integer playerId = GameJwtUtils.getPlayerIdByRequest(request);
        heroService.createHero(playerId, cCreateHeroMsg.getHeroTypeId());
        return SRet.success();
    }

    @PostMapping("/getHeroList")
    public SRet getHeroList(HttpServletRequest request){
        Integer playerId = GameJwtUtils.getPlayerIdByRequest(request);
//        通过heroService.getHeroList获取列表
        SRet heroList = heroService.getHeroList(playerId);
        return heroList;
    }

    @PostMapping("/heroDetail")
    public SRet heroDetail(HttpServletRequest request, @RequestBody CHeroDetailMsg cHeroDetailMsg){
        Integer playerId = GameJwtUtils.getPlayerIdByRequest(request);
        SRet<SHeroDetailMsg> heroSRet = heroService.herDetail(playerId, cHeroDetailMsg.getHeroId());
        return heroSRet;
    }

    @PostMapping("/lvUp")
    public SRet lvUp(HttpServletRequest request, @RequestBody CHeroLvUpMsg cHeroLvUpMsg){
        Integer playerId = GameJwtUtils.getPlayerIdByRequest(request);
        SRet<SHeroLvUpMsg> heroSRet = heroService.lvUp(playerId, cHeroLvUpMsg.getHeroId());
        return heroSRet;
    }

    @PostMapping("/starUp")
    public SRet starUp(HttpServletRequest request, @RequestBody CHeroStarUpMsg cHeroStarUpMsg){
        Integer playerId = GameJwtUtils.getPlayerIdByRequest(request);
        SRet<SHeroLvUpMsg> heroSRet = heroService.starUp(playerId, cHeroStarUpMsg.getHeroId(), cHeroStarUpMsg.getConsumeHeroes());
        return heroSRet;
    }
}
